//报关报检业务代理人
$(function () {
    //初始化特殊关系确认、价格影响确认、支付特许权使用费确认显示值
    var SPECIAL_RELATIONSHIP_CONFIRM_CODE = $("#SPECIAL_RELATIONSHIP_CONFIRM_CODE").val();
    var PRICE_IMPACT_CONFIRM_CODE = $("#PRICE_IMPACT_CONFIRM_CODE").val();
    var PAYMENT_ROYALTIES_CONFIRM_CODE = $("#PAYMENT_ROYALTIES_CONFIRM_CODE").val();
    if (SPECIAL_RELATIONSHIP_CONFIRM_CODE == "0") {
        $("#SPECIAL_RELATIONSHIP_CONFIRM").val("是");
    } else if (SPECIAL_RELATIONSHIP_CONFIRM_CODE == "1") {
        $("#SPECIAL_RELATIONSHIP_CONFIRM").val("否");
    }
    if (PRICE_IMPACT_CONFIRM_CODE == "0") {
        $("#PRICE_IMPACT_CONFIRM").val("是");
    } else if (PRICE_IMPACT_CONFIRM_CODE == "1") {
        $("#PRICE_IMPACT_CONFIRM").val("否");
    }
    if (PAYMENT_ROYALTIES_CONFIRM_CODE == "0") {
        $("#PAYMENT_ROYALTIES_CONFIRM").val("是");
    } else if (PAYMENT_ROYALTIES_CONFIRM_CODE == "1") {
        $("#PAYMENT_ROYALTIES_CONFIRM").val("否");
    }

    //报关报检业务代理人
    dropdownClickEvent("#declaration_sup_id");
    $("#declaration_sup_id").autocomplete({
                                              source: function (request, response) {
                                                  var port_code = $("#DECLARATION_PORT_CODE").val();
                                                  $.ajax({
                                                             url: "declarationOffer-findDeclarationByPortName.do",
                                                             dataType: "json",
                                                             type: "post",
                                                             data: {
                                                                 port_code: port_code
                                                             },
                                                             success: function (data) {
                                                                 response(
                                                                     $.map(data,
                                                                           function (item) {
                                                                               return {
                                                                                   id: item.declaration_company_id,
                                                                                   name: item.declaration_company,
                                                                                   com_customs_code: item.com_customs_code,
                                                                                   value: item.declaration_company
                                                                               };
                                                                           }));
                                                             }
                                                         });
                                              },
                                              minLength: 0,
                                              autoFocus: true,
                                              select: function (event, ui) {
                                                  $("#declaration_sup").val(ui.item.id);
                                                  $("#SHENBAO_COMPANY_CO").val(
                                                      ui.item.com_customs_code);
                                                  $("#SHENBAO_COMPANY_NAME").val(ui.item.name);
                                                  $.ajax({
                                                             url: "declarationOffer-getDeclarationOfferFree.do",
                                                             dataType: "json",
                                                             type: "post",
                                                             data: {
                                                                 declaration_company_id: ui.item.id
                                                             },
                                                             success: function (data) {
                                                                 console.log(data);
                                                                 if (data != null) {
                                                                     $("#declarationFree").text(
                                                                         data.declaration_amount);
                                                                     if (data.container_amount
                                                                         == ""
                                                                         || data.container_amount
                                                                            == 0) {
                                                                         $("#containerNum_val").hide();
                                                                         $("#containerNum").hide();
                                                                     } else {
                                                                         $("#containerNum").text(
                                                                             data.container_amount);
                                                                         $("#containerNum_val").show();
                                                                         $("#containerNum").show();
                                                                     }
                                                                     if (data.remark
                                                                         == null) {
                                                                         $("#offer_remark").hide();
                                                                     } else {
                                                                         $("#offer_remark").text(
                                                                             "说明："
                                                                             + data.remark);
                                                                         $("#offer_remark").show();
                                                                     }
                                                                     $("#showDeclarationFree").show();
                                                                 } else {
                                                                     $("#showDeclarationFree").hide();
                                                                 }
                                                             }
                                                         });
                                              }
                                          });

});

//特殊关系确认
dropdownClickEvent("#SPECIAL_RELATIONSHIP_CONFIRM");

$("#SPECIAL_RELATIONSHIP_CONFIRM").autocomplete({
                                                    autoFocus: true,
                                                    minLength: 0,
                                                    source: function (request, response) {
                                                        var term = request.trem;
                                                        var data = confirm_type;
                                                        var d = $.map(data, function (item) {
                                                            return {
                                                                label: item.code + " " + item.name,
                                                                code: item.code,
                                                                name: item.name
                                                            };
                                                        });
                                                        var matcher = new RegExp($.ui.autocomplete.escapeRegex(
                                                            request.term), "i");
                                                        response($.grep(d, function (value) {
                                                            value = value.label;
                                                            return matcher.test(value);
                                                        }));
                                                    }, select: function (event, ui) {
        $(this).val(ui.item.name);
        $("#SPECIAL_RELATIONSHIP_CONFIRM_CODE").val(ui.item.code);
        return false;
    }
                                                });

//特殊关系确认
dropdownClickEvent("#PRICE_IMPACT_CONFIRM");
$("#PRICE_IMPACT_CONFIRM").autocomplete({
                                            autoFocus: true,
                                            minLength: 0,
                                            source: function (request, response) {
                                                var term = request.trem;
                                                var data = confirm_type;
                                                var d = $.map(data, function (item) {
                                                    return {
                                                        label: item.code + " " + item.name,
                                                        code: item.code,
                                                        name: item.name
                                                    };
                                                });
                                                var matcher = new RegExp($.ui.autocomplete.escapeRegex(
                                                    request.term), "i");
                                                response($.grep(d, function (value) {
                                                    value = value.label;
                                                    return matcher.test(value);
                                                }));
                                            }, select: function (event, ui) {
        $(this).val(ui.item.name);
        $("#PRICE_IMPACT_CONFIRM_CODE").val(ui.item.code);
        return false;
    }
                                        });

//支付特许权使用费确认
dropdownClickEvent("#PAYMENT_ROYALTIES_CONFIRM");
$("#PAYMENT_ROYALTIES_CONFIRM").autocomplete({
                                                 autoFocus: true,
                                                 minLength: 0,
                                                 source: function (request, response) {
                                                     var term = request.trem;
                                                     var data = confirm_type;
                                                     var d = $.map(data, function (item) {
                                                         return {
                                                             label: item.code + " " + item.name,
                                                             code: item.code,
                                                             name: item.name
                                                         };
                                                     });
                                                     var matcher = new RegExp($.ui.autocomplete.escapeRegex(
                                                         request.term), "i");
                                                     response($.grep(d, function (value) {
                                                         value = value.label;
                                                         return matcher.test(value);
                                                     }));
                                                 }, select: function (event, ui) {
        $(this).val(ui.item.name);
        $("#PAYMENT_ROYALTIES_CONFIRM_CODE").val(ui.item.code);
        return false;
    }
                                             });

//出口口岸下拉
dropdownClickEvent("#EXPORT_PORT");
$("#EXPORT_PORT").autocomplete({
                                   autoFocus: true,
                                   minLength: 0,
                                   source: function (request, response) {
                                       var term = request.trem;
                                       var data = export_port;
                                       var d = $.map(data, function (item) {
                                           return {
                                               label: item.code + " " + item.name,
                                               code: item.code,
                                               name: item.name
                                           };
                                       });
                                       var matcher = new RegExp($.ui.autocomplete.escapeRegex(
                                           request.term), "i");
                                       response($.grep(d, function (value) {
                                           value = value.label;
                                           return matcher.test(value);
                                       }));
                                   }, select: function (event, ui) {
        $(this).val(ui.item.name);
        $("#EXPORT_PORT_CODE").val(ui.item.code);
        return false;
    }
                               });

//申报口岸下拉
dropdownClickEvent("#DECLARATION_PORT");
$("#DECLARATION_PORT").autocomplete({
                                        autoFocus: true,
                                        minLength: 0,
                                        delay: 0,
                                        source: function (request, response) {
                                            $.ajax({
                                                       url: "declarationOffer-shenBaoPortName.",
                                                       dataType: "json",
                                                       type: "post",
                                                       data: {
                                                           k: request.term
                                                       },
                                                       success: function (data) {
                                                           response($.map(data,
                                                                          function (item) {
                                                                              return {
                                                                                  label: item.port_code
                                                                                         + " "
                                                                                         + item.port,
                                                                                  code: item.port_code,
                                                                                  name: item.port
//							id : item.port_code,
//							name : item.port,
//							value : item.port
                                                                              };
                                                                          }));
                                                       }
                                                   });
                                        },
                                        select: function (event, ui) {
                                            $(this).val(ui.item.name);
                                            $("#DECLARATION_PORT_CODE").val(ui.item.code);
                                            $("#declaration_sup_id").val("");
                                            $("#declaration_sup").val("");
                                            $("#showDeclarationFree").hide();
                                            var CONCRETE_GOODS_PACKAGE = $(
                                                "#CONCRETE_GOODS_PACKAGE").val();
                                            var OTHER_GOODS_ADDR_SHOW = $(
                                                "#OTHER_GOODS_ADDR_SHOW").val();
                                            if (CONCRETE_GOODS_PACKAGE == "") {
                                                if (OTHER_GOODS_ADDR_SHOW == "") {
                                                    $("#REMARK").val(ui.item.name + ",结汇,退税");
                                                } else {
                                                    $("#REMARK").val(ui.item.name + ",结汇,退税; 其他货源地:"
                                                                     + OTHER_GOODS_ADDR_SHOW);
                                                }
                                            } else {
                                                if (OTHER_GOODS_ADDR_SHOW == "") {
                                                    $("#REMARK").val(ui.item.name + ",结汇,退税; 包装种类："
                                                                     + CONCRETE_GOODS_PACKAGE);
                                                } else {
                                                    $("#REMARK").val(ui.item.name + ",结汇,退税; 其他货源地:"
                                                                     + OTHER_GOODS_ADDR_SHOW
                                                                     + "; 包装种类："
                                                                     + CONCRETE_GOODS_PACKAGE);
                                                }
                                            }
                                            return false;
                                        }

                                    });

//miniLength为0时，下拉框输入框被点击或者获得焦点会打开下拉框
function dropdownClickEvent(id) {
    var obj = $(id);
//		obj.bind("focus",function(event){obj.autocomplete("search");});
    obj.bind("click", function (event) {
        obj.autocomplete("search");
    });
}

//
//	//提交
//	function submit_decla(){
//		//报关商品
//		var decla_goods_trs = $("#goodsListTB tr");
//		if(decla_goods_trs.length > 1){
//			var temp_tr0_tds = $(decla_goods_trs[0]).find("td");
//			var index = 0;
//			var temp_goodsInput = "";
//			for(var i=1; i<decla_goods_trs.length; i++){
//				var dGoodsTds = $(decla_goods_trs[i]).find("td");
//				for(var j=0; j<temp_tr0_tds.length; j++){
//					if($(temp_tr0_tds[j]).attr("lang") &&
// $(temp_tr0_tds[j]).attr("lang")!="declara_num"){ var dGoodInputs = dGoodsTds[j].find("input");
// if(dGoodInputs.length!=0){ temp_goodsInput = temp_goodsInput + "<input type='hidden'
// name='declare.commodities[" + index + "]." + $(temp_tr0_tds[j]).attr("lang") + "' value=\"" +
// $(dGoodsInputs).val()+"\" \/>"; }else{ temp_goodsInput = temp_goodsInput + "<input type='hidden'
// name='declare.commodities[" + index + "]." + $(temp_tr0_tds[j]).attr("lang") + "' value=\"" +
// $(dGoodsTds[j]).text()+"\" \/>"; } } } index++; } $("#input_declare_goods").html("");
// $("#input_declare_goods").html(temp_goodsInput); } //报关随附单 var decla_suifu_trs =
// $("#suifudanListTB tr"); if(decla_suifu_trs.length > 1){ var temp_tr0_tds =
// $(decla_suifu_trs[0]).find("td"); var index = 0; var temp_goodsInput = ""; for(var i=1;
// i<decla_suifu_trs.length; i++){ var dGoodsTds = $(decla_suifu_trs[i]).find("td"); for(var j=0;
// j<temp_tr0_tds.length; j++){ if($(temp_tr0_tds[j]).attr("lang") &&
// $(temp_tr0_tds[j]).attr("lang")!="suifudan_num"){ temp_goodsInput = temp_goodsInput + "<input
// type='hidden' name='declare.suiFuDans[" + index +"]." + $(temp_tr0_tds[j]).attr("lang") + "'
// value=\"" + $(dGoodsTds[j]).text()+"\" \/>"; } } index++; }
// $("#input_declare_suifudans").html(""); $("#input_declare_suifudans").html(temp_goodsInput); } }
$.ajax({
           url: "hgdata-initData.do", success: function (data) {
        var customs = data.data.HGD_2;

    }
       });

function reflashIndex() {
    $("#goods_list tr").each(function (n, k) {
        $(this).find("td").eq(0).html(n);
    });
}

function cleanGoods_input() {
    $("#goods_input").find("input[type!=button]").val("");
}

//检测第一步必填项
function firstStepRequired() {
    var INDEX = $("#INDEX").val();//序号
    var HANDBOOK_ITEM_NO = $("#HANDBOOK_ITEM_NO").val();//手册项号
    var CODE_T = $("#CODE_T").val();//税号
    var CODE_S = $("#CODE_S").val();//税号附号
    var NAME = $("#NAME").val();//商品名称
    var KEY_ELEMENTS = $("#KEY_ELEMENTS").val();//规格型号
    var GOODS_MODE = $("#GOODS_MODE").val();//要素
    var KEY_ELEMENTS = $("#KEY_ELEMENTS").val();//规格手填的
    var COUNT = $("#COUNT").val();//计价数量
    var UNIT = $("#UNIT").val();//计价单位
    var UNIT_PRICE = $("#UNIT_PRICE").val();//单价
    var TOTAL_PRICE = $("#TOTAL_PRICE").val();//总价
    var CURRENCY = $("#CURRENCY").val();//币制
    var LEGAL_COUNT = $("#LEGAL_COUNT").val();//法定数量
    var LEGAL_UNIT = $("#LEGAL_UNIT").val();//法定单位
    var DESTINATION = $("#DESTINATION").val();//目的地
    var GOODS_NUMBER = $("#GOODS_NUMBER").val();//件数
    var PACKAGE_TYPE = $("#PACKAGE_TYPE").val();//具体包装种类
    var GOODS_NET_WEIGHT = $("#GOODS_NET_WEIGHT").val();//净重
    var GOODS_GROSS_WEIGHT = $("#GOODS_GROSS_WEIGHT").val();//毛重
    var SECOND_COUNT = $("#SECOND_COUNT").val();//第二数量
    var SECOND_UNIT = $("#SECOND_UNIT").val();//第二计量单位
    var GOODS_LEVYMODE = $("#GOODS_LEVYMODE").val();//征免
    var ID = $("#ID").val();//ID
    var CONTAINER_NO = $("#CONTAINER_NO").val();
    var VERSION_NO = $("#VERSION_NO").val();//版本号
    var ORIGIN_COUNTRY = $("#ORIGIN_COUNTRY").val();//原产国

    //设置运抵国和指运港的值
    $("#ARRIVED_COUNTRY_SHOW").val(DESTINATION);
    $("#ARRIVED_PORT_SHOW").val(DESTINATION);

    var isRecordInfo = $("#isRecordInfo").val();
    var RECORD_ID = $("#RECORD_ID").val();
    var declareId = $("#declareId").val();

    //获取第二数量和第二单位的disabled属性值
    var SECOND_COUNT_DISABLED_VAL = $("#SECOND_COUNT").attr("disabled");
    var SECOND_UNIT_DISABLED_VAL = $("#SECOND_UNIT").attr("disabled");

    if (!NAME) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">商品名称不能为空,请填写好商品名称再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#NAME").focus();
            }, function () {
                $("#NAME").focus();
            });
        return true;
    }
//		else if(!KEY_ELEMENTS) {
//			jw.confirm('<div><p style="font-style: normal;font-size:
// 16px;color:red;">规格型号不能为空,请填写好规格型号再确定货物！</p></div>', function () { $(this).dialog('destroy');
// $("#KEY_ELEMENTS").focus(); }, function() { $("#KEY_ELEMENTS").focus(); }); return true; }
    else if (!GOODS_MODE) {
        if (isRecordInfo == "F") {
            jw.confirm(
                '<div><p style="font-style: normal;font-size: 16px;color:red;">要素不能为空,请填写好要素再确定货物！</p></div>',
                function () {
                    $(this).dialog('destroy');
                    $("#GOODS_MODE").focus();
                }, function () {
                    $("#GOODS_MODE").focus();
                });
            return true;
        }
    } else if (!CODE_T) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">税号不能为空,请填写好税号再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#CODE_T").focus();
            }, function () {
                $("#CODE_T").focus();
            });
        return true;
    } else if (!CODE_S) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">税号附号不能为空,请填写好税号附号再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#CODE_S").focus();
            }, function () {
                $("#CODE_S").focus();
            });
        return true;
    } else if (!COUNT) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">计价数量不能为空,请填写好计价数量再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#COUNT").focus();
            }, function () {
                $("#COUNT").focus();
            });
        return true;
    } else if (!UNIT) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">计价单位不能为空,请填写好计价单位再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#UNIT").focus();
            }, function () {
                $("#UNIT").focus();
            });
        return true;
    } else if (!UNIT_PRICE) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">单价不能为空,请填写好单价再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#UNIT_PRICE").focus();
            }, function () {
                $("#UNIT_PRICE").focus();
            });
        return true;
    } else if (!TOTAL_PRICE) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">总价不能为空,请填写好总价再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#TOTAL_PRICE").focus();
            }, function () {
                $("#TOTAL_PRICE").focus();
            });
        return true;
    } else if (!CURRENCY) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">币制不能为空,请填写好币制再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#CURRENCY").focus();
            }, function () {
                $("#CURRENCY").focus();
            });
        return true;
    } else if (!LEGAL_COUNT) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">法定数量不能为空,请填写好法定数量再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#LEGAL_COUNT").focus();
            }, function () {
                $("#LEGAL_COUNT").focus();
            });
        return true;
    } else if (!LEGAL_UNIT) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">法定单位不能为空,请填写好法定单位再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#LEGAL_UNIT").focus();
            }, function () {
                $("#LEGAL_UNIT").focus();
            });
        return true;
    } else if (!DESTINATION) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">目的地不能为空,请填写好目的地再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#DESTINATION").focus();
            }, function () {
                $("#DESTINATION").focus();
            });
        return true;
    } else if (!GOODS_NUMBER) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">件数不能为空,请填写好件数再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GOODS_NUMBER").focus();
            }, function () {
                $("#GOODS_NUMBER").focus();
            });
        return true;
    } else if (!PACKAGE_TYPE) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">具体包装种类不能为空,请填写好具体包装种类再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#PACKAGE_TYPE").focus();
            }, function () {
                $("#PACKAGE_TYPE").focus();
            });
        return true;
    } else if (!GOODS_NET_WEIGHT) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">净重不能为空,请填写好净重再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GOODS_NET_WEIGHT").focus();
            }, function () {
                $("#GOODS_NET_WEIGHT").focus();
            });
        return true;
    } else if (!GOODS_GROSS_WEIGHT) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">毛重不能为空,请填写好毛重再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GOODS_GROSS_WEIGHT").focus();
            }, function () {
                $("#GOODS_GROSS_WEIGHT").focus();
            });
        return true;
    } else if (!SECOND_COUNT && SECOND_COUNT_DISABLED_VAL != "disabled") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">第二数量不能为空,请填写好第二数量再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#SECOND_COUNT").focus();
            }, function () {
                $("#SECOND_COUNT").focus();
            });
        return true;
    } else if (!SECOND_UNIT && SECOND_UNIT_DISABLED_VAL != "disabled") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">第二计量单位不能为空,请填写好第二计量单位再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#SECOND_UNIT").focus();
            }, function () {
                $("#SECOND_UNIT").focus();
            });
        return true;
    } else if (!GOODS_LEVYMODE) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">征免不能为空,请填写好征免再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GOODS_LEVYMODE").focus();
            }, function () {
                $("#GOODS_LEVYMODE").focus();
            });
        return true;
    } else if (!ORIGIN_COUNTRY) {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">原产国不能为空,请填写好原产国再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#ORIGIN_COUNTRY").focus();
            }, function () {
                $("#ORIGIN_COUNTRY").focus();
            });
        return true;
    }
}

function confirmDeclare() {
    var INDEX = $("#INDEX").val();//序号
    var HANDBOOK_ITEM_NO = $("#HANDBOOK_ITEM_NO").val();//手册项号
    var CODE_T = $("#CODE_T").val();//税号
    var CODE_S = $("#CODE_S").val();//税号附号
    var NAME = $("#NAME").val();//商品名称
    var GOODS_MODE = $("#GOODS_MODE").val();//规格型号
    var KEY_ELEMENTS = $("#KEY_ELEMENTS").val();//规格手填的
    var COUNT = $("#COUNT").val();//计价数量
    var UNIT = $("#UNIT").val();//计价单位
    var UNIT_PRICE = $("#UNIT_PRICE").val();//单价
    var TOTAL_PRICE = $("#TOTAL_PRICE").val();//总价
    var CURRENCY = $("#CURRENCY").val();//币制
    var LEGAL_COUNT = $("#LEGAL_COUNT").val();//法定数量
    var LEGAL_UNIT = $("#LEGAL_UNIT").val();//法定单位
    var DESTINATION = $("#DESTINATION").val();//目的地
    var DESTINATION_CODE = $("#DESTINATION_CODE").val();//目的地代码
    var ORIGIN_COUNTRY = $("#ORIGIN_COUNTRY").val();//原产国
    var ORIGIN_COUNTRY_CODE = $("#ORIGIN_COUNTRY_CODE").val();//原产国
    var GOODS_NUMBER = $("#GOODS_NUMBER").val();//件数
    var PACKAGE_TYPE = $("#PACKAGE_TYPE").val();//具体包装种类
    var GOODS_NET_WEIGHT = $("#GOODS_NET_WEIGHT").val();//净重
    var GOODS_GROSS_WEIGHT = $("#GOODS_GROSS_WEIGHT").val();//毛重
    var SECOND_COUNT = $("#SECOND_COUNT").val();//第二数量
    var SECOND_UNIT = $("#SECOND_UNIT").val();//第二计量单位
    var GOODS_LEVYMODE = $("#GOODS_LEVYMODE").val();//征免
    var ID = $("#ID").val();//ID
    var CONTAINER_NO = $("#CONTAINER_NO").val();
    var VERSION_NO = $("#VERSION_NO").val();//版本号
    var PACKINGLIST_REMARK = $("#PACKINGLIST_REMARK").val();//装箱单备注
    //设置运抵国和指运港的值
    $("#ARRIVED_COUNTRY_SHOW").val(DESTINATION);
    $("#ARRIVED_COUNTRY_CODE").val(DESTINATION_CODE);
    $("#ARRIVED_PORT_SHOW").val(DESTINATION);
    $("#ARRIVED_PORT_CODE").val(DESTINATION_CODE);

    var isRecordInfo = $("#isRecordInfo").val();
    var RECORD_ID = $("#RECORD_ID").val();
    var declareId = $("#declareId").val();

    if (isRecordInfo == "T") {
        if (RECORD_ID == "") {
            jw.confirm(
                '<div><p style="font-style: normal;font-size: 16px;color:red;">手册号不能为空,请填写好手册号再确定货物！</p></div>',
                function () {
                    $(this).dialog('destroy');
                    $("#RECORD_ID").focus();
                }, function () {
                    $("#RECORD_ID").focus();
                });
            return;
        } else if (HANDBOOK_ITEM_NO == "") {
            jw.confirm(
                '<div><p style="font-style: normal;font-size: 16px;color:red;">手册项号不能为空,请填写好手册项号再确定货物！</p></div>',
                function () {
                    $(this).dialog('destroy');
                    $("#HANDBOOK_ITEM_NO").focus();
                }, function () {
                    $("#HANDBOOK_ITEM_NO").focus();
                });
            return;
        }
    }

    if (firstStepRequired()) {
        return;
    }

    if (UNIT == LEGAL_UNIT && COUNT != LEGAL_COUNT) {
        console.log("1:{UNIT : " + UNIT + ", LEGAL_COUNT: " + LEGAL_COUNT + "}");
        console.log();
        alert("数量单位不一致");
        return;
    }
    if (UNIT == SECOND_UNIT && COUNT != SECOND_COUNT) {
        console.log(
            "2:{UNIT : " + UNIT + ", SECOND_UNIT: " + SECOND_UNIT + ", COUNT:" + COUNT + "}");
        console.log();
        alert("数量单位不一致");
        return;
    }
    if (LEGAL_UNIT == SECOND_UNIT && LEGAL_COUNT != SECOND_COUNT) {
        console.log("3:{LEGAL_UNIT : " + LEGAL_UNIT + ", SECOND_UNIT: " + SECOND_UNIT + "}");
        alert("数量单位不一致");
        return;
    }

    var good_list_th = $("#goods_list").find("th");
    var index = $("#goods_list table tbody>tr:last td").eq(0).html();
    if (INDEX) {
        index = INDEX;
    } else {
        index = (!index ? "1" : parseInt(index) + 1);
    }
    var trStr = "";
//			good_list_th.each(function(){
//				var lang=$(this).attr("lang");
//				if(lang){
//					switch (lang) {
//					case 'INDEX':
//						trStr+="<td name='INDEX' lang='index'>"+index+"</td>";
//						break;
//					case 'HANDBOOK_ITEM_NO':
//						trStr+="<td name='HANDBOOK_ITEM_NO' lang='handbook_item_no'
// style='display: none;'>"+HANDBOOK_ITEM_NO+"</td>"; break; case 'CODE_T': trStr+="<td
// name='CODE_T' lang='code_t'>"+CODE_T+"</td>"; break; case 'CODE_S': trStr+="<td name='CODE_S'
// lang='code_s' style='display: none;'>"+CODE_S+"</td>"; break; case 'NAME': trStr+="<td
// name='NAME' lang='name'>"+NAME+"</td>"; break; case 'GOODS_MODE': trStr+="<td name='GOODS_MODE'
// lang='goods_mode'>"+GOODS_MODE+"</td>"; break; case 'COUNT': trStr+="<td name='COUNT'
// lang='count'>"+COUNT+"</td>"; break; case 'UNIT': trStr+="<td name='UNIT'
// lang='unit'>"+UNIT+"</td>"; break; case 'UNIT_PRICE': trStr+="<td name='UNIT_PRICE'
// lang='unit_price' style='display: none;'>"+UNIT_PRICE+"</td>"; break; case 'TOTAL_PRICE':
// trStr+="<td name='TOTAL_PRICE' lang='total_price'>"+TOTAL_PRICE+"</td>"; break; case 'CURRENCY':
// trStr+="<td name='CURRENCY' lang='currency'>"+CURRENCY+"</td>"; break; case 'LEGAL_COUNT':
// trStr+="<td name='LEGAL_COUNT' lang='legal_count' style='display: none;'>"+LEGAL_COUNT+"</td>";
// break; case 'LEGAL_UNIT': trStr+="<td name='LEGAL_UNIT' lang='legal_unit' style='display:
// none;'>"+LEGAL_UNIT+"</td>"; break; case 'DESTINATION': trStr+="<td name='DESTINATION'
// lang='destination'>"+DESTINATION+"</td>"; break; case 'GOODS_NUMBER': trStr+="<td
// name='GOODS_NUMBER' lang='goods_number' style='display: none;'>"+GOODS_NUMBER+"</td>"; break;
// case 'GOODS_NET_WEIGHT': trStr+="<td name='GOODS_NET_WEIGHT' lang='goods_net_weight'
// style='display: none;'>"+GOODS_NET_WEIGHT+"</td>"; break; case 'GOODS_GROSS_WEIGHT': trStr+="<td
// name='GOODS_GROSS_WEIGHT' lang='goods_gross_weight' style='display:
// none;'>"+GOODS_GROSS_WEIGHT+"</td>"; break; case 'SECOND_COUNT': trStr+="<td name='SECOND_COUNT'
// lang='second_count' style='display: none;'>"+SECOND_COUNT+"</td>"; break; case 'SECOND_UNIT':
// trStr+="<td name='SECOND_UNIT' lang='second_unit' style='display: none;'>"+SECOND_UNIT+"</td>";
// break; case 'LEVYMODE': trStr+="<td name='LEVYMODE' lang='levymode' style='display:
// none;'>"+LEVYMODE+"</td>"; break; case 'OPERATION': trStr+="<td name='OPERATION'><a
// href='javascript:;' onclick='javascript:addGoods();'>增加</a>" + "<a href='javascript:;'
// onclick='javascript:modGoods(this);'>修改</a>" + "<a href='javascript:;'
// onclick='javascript:delGoods(this);'>删除</a>" + "<a href='javascript:;'
// onclick='javascript:copyGoods(this);'>复制</a></td>"; break; } } });

    good_list_th.each(function () {
        var lang = $(this).attr("lang");
        if (lang) {
            switch (lang) {
                case 'index_num':
                    trStr += "<td name='INDEX' lang='index'>" + index + "</td>";
                    break;
                case 'handbook_item_no':
//						var isRecordInfo = $("#isRecordInfo").val();
//						var RECORD_ID = $("#RECORD_ID").val();
                    if (isRecordInfo == "T") {
                        trStr +=
                            "<td name='HANDBOOK_ITEM_NO' lang='handbook_item_no' >"
                            + HANDBOOK_ITEM_NO + "</td>";
                    } else {
                        if (RECORD_ID == null || RECORD_ID == "") {
                            trStr +=
                                "<td name='HANDBOOK_ITEM_NO' lang='handbook_item_no' style='display: none;' >"
                                + HANDBOOK_ITEM_NO + "</td>";
                        } else {
                            trStr +=
                                "<td name='HANDBOOK_ITEM_NO' lang='handbook_item_no'>"
                                + HANDBOOK_ITEM_NO + "</td>";
                        }
                    }
                    break;
                case 'code_t':
                    trStr += "<td name='CODE_T' lang='code_t'>" + CODE_T + "</td>";
                    break;
                case 'code_s':
                    trStr +=
                        "<td name='CODE_S' lang='code_s' style='display: none;'>" + CODE_S
                        + "</td>";
                    break;
                case 'name':
                    trStr += "<td name='NAME' lang='name'>" + NAME + "</td>";
                    break;
                case 'goods_mode':
                    trStr +=
                        "<td name='GOODS_MODE' lang='goods_mode' style='display: none;'>"
                        + GOODS_MODE + "</td>";
                    break;
                case 'key_elements':
                    trStr +=
                        "<td name='KEY_ELEMENTS' lang='key_elements'>" + KEY_ELEMENTS + "</td>";
                    break;
                case 'count':
                    trStr += "<td name='COUNT' lang='count'>" + COUNT + "</td>";
                    break;
                case 'unit':
                    trStr += "<td name='UNIT' lang='unit'>" + UNIT + "</td>";
                    break;
                case 'unit_price':
                    trStr +=
                        "<td name='UNIT_PRICE' lang='unit_price' style='display: none;'>"
                        + UNIT_PRICE + "</td>";
                    break;
                case 'total_price':
                    trStr += "<td name='TOTAL_PRICE' lang='total_price'>" + TOTAL_PRICE + "</td>";
                    break;
                case 'currency':
                    trStr += "<td name='CURRENCY' lang='currency'>" + CURRENCY + "</td>";
                    break;
                case 'legal_count':
                    trStr +=
                        "<td name='LEGAL_COUNT' lang='legal_count' style='display: none;'>"
                        + LEGAL_COUNT + "</td>";
                    break;
                case 'legal_unit':
                    trStr +=
                        "<td name='LEGAL_UNIT' lang='legal_unit' style='display: none;'>"
                        + LEGAL_UNIT + "</td>";
                    break;
                case 'destination':
                    trStr += "<td name='DESTINATION' lang='destination'>" + DESTINATION + "</td>";
                    break;
                case 'goods_number':
                    trStr +=
                        "<td name='GOODS_NUMBER' lang='goods_number' style='display: none;'>"
                        + GOODS_NUMBER + "</td>";
                    break;
                case 'package_type':
                    trStr +=
                        "<td name='PACKAGE_TYPE' lang='package_type' style='display: none;'>"
                        + PACKAGE_TYPE + "</td>";
                    break;
                case 'goods_net_weight':
                    trStr +=
                        "<td name='GOODS_NET_WEIGHT' lang='goods_net_weight' style='display: none;'>"
                        + GOODS_NET_WEIGHT + "</td>";
                    break;
                case 'goods_gross_weight':
                    trStr +=
                        "<td name='GOODS_GROSS_WEIGHT' lang='goods_gross_weight' style='display: none;'>"
                        + GOODS_GROSS_WEIGHT + "</td>";
                    break;
                case 'second_count':
                    trStr +=
                        "<td name='SECOND_COUNT' lang='second_count' style='display: none;'>"
                        + SECOND_COUNT + "</td>";
                    break;
                case 'second_unit':
                    trStr +=
                        "<td name='SECOND_UNIT' lang='second_unit' style='display: none;'>"
                        + SECOND_UNIT + "</td>";
                    break;
                case 'levymode':
                    trStr +=
                        "<td name='LEVYMODE' lang='levymode' style='display: none;'>"
                        + GOODS_LEVYMODE + "</td>";
                    break;
                case 'id':
                    trStr += "<td name='ID' lang='id' style='display: none;'>" + ID + "</td>"
                    break;
                case 'operation':
                    trStr += "<td name='OPERATION'>" +
                             "<a class='ui-button ui-widget ui-state-default ui-corner-all' href='javascript:;' onclick='javascript:addGoods(this);'>增加</a>"
                             +
                             "<a class='ui-button ui-widget ui-state-default ui-corner-all' href='javascript:;' onclick='javascript:modGoods(this);'>修改</a>"
                             +
                             "<a class='ui-button ui-widget ui-state-default ui-corner-all' href='javascript:;' onclick='javascript:delGoods(this);'>删除</a>"
                             +
                             "<a class='ui-button ui-widget ui-state-default ui-corner-all' href='javascript:;' onclick='javascript:copyGoods(this);'>复制</a>"
                             +
                             "<a class='ui-button ui-widget ui-state-default ui-corner-all' href='javascript:;' onclick='javascript:upGoods(this);'>上移</a>"
                             +
                             "<a class='ui-button ui-widget ui-state-default ui-corner-all' href='javascript:;' onclick='javascript:downGoods(this);'>下移</a>"
                             +
                             "</td>";
                    break;
                case 'container_no':
                    trStr +=
                        "<td name='CONTAINER_NO' lang='container_no' style='display: none;'>"
                        + CONTAINER_NO + "</td>"
                    break;
                case 'version_no':
                    trStr +=
                        "<td name='VERSION_NO' lang='version_no' style='display: none;'>"
                        + VERSION_NO + "</td>"
                    break;
                case 'packinglist_remark':
                    trStr +=
                        "<td name='PACKINGLIST_REMARK' lang='packinglist_remark' style='display: none;'>"
                        + PACKINGLIST_REMARK + "</td>"
                    break;
                case 'destination_code':
                    trStr +=
                        "<td name='DESTINATION_CODE' lang='destination_code' style='display: none;'>"
                        + DESTINATION_CODE + "</td>"
                    break;
                case 'origin_country':
                    trStr +=
                        "<td name='ORIGIN_COUNTRY' lang='origin_country' style='display: none;'>"
                        + ORIGIN_COUNTRY + "</td>"
                    break;
                case 'origin_country_code':
                    trStr +=
                        "<td name='ORIGIN_COUNTRY_CODE' lang='origin_country_code' style='display: none;'>"
                        + ORIGIN_COUNTRY_CODE + "</td>"
                    break;
            }

        }
    });

    if (INDEX) {
        $("#goods_list table tr").eq(INDEX).html(trStr);
    } else {
        $("#goods_list table").append($("<tr>" + trStr + "</tr>"));
    }

    $("#goods_list").css("display", "block");
    $("#goods_input").css("display", "none");
    cleanGoods_input();
    refreshGoodsTotal();
}

function cancelDeclare() {
    $("#goods_list").css("display", "block");
    $("#goods_input").css("display", "none");
    cleanGoods_input();
    refreshGoodsTotal();
}

function addGoods(obj) {
    //进入添加时，隐藏保存、提交按钮
//		$("#sumit1").css("display","none");
//		$("#tijiao1").css("display","none");
//		var goodsLength = $("#goods_list table tr").length-1;
//		if(goodsLength == 20) {
//			alert("报关商品录入项不能超过20项!");
//			return;
//		}
    var tr = $(obj).parent().parent();
    var d = tr.find("td:eq(5)").text();
    setDefaultValue("#DESTINATION", d);
    setDefaultValue("#GOODS_LEVYMODE", "照章征税");
    setDefaultValue("#CURRENCY", "美元");
    setDefaultValue("#ORIGIN_COUNTRY", "中国");
    setDefaultValue("#ORIGIN_COUNTRY_CODE", "142");
    $("#goods_list").css("display", "none");
    $("#goods_input").css("display", "block");
}

function modGoods(obj) {
    $("#goods_list").css("display", "none");
    $("#goods_input").css("display", "block");
    //进入修改时，隐藏保存、提交按钮
//		$("#sumit1").css("display","none");
//		$("#tijiao1").css("display","none");
    var tr = $(obj).parent().parent();
    tr.find("td").each(function () {
        var lang = $(this).attr("name");
        var value = $(this).html();
        switch (lang) {
            case 'INDEX':
                $("#INDEX").val(value);
                break;
            case 'HANDBOOK_ITEM_NO':
                $("#HANDBOOK_ITEM_NO").val(value);
                break;
            case 'CODE_T':
                $("#CODE_T").val(value);
                break;
            case 'CODE_S':
                $("#CODE_S").val(value);
                break;
            case 'NAME':
                $("#NAME").val(value);
                break;
            case 'GOODS_MODE':
                $("#GOODS_MODE").val(value);
                break;
            case 'KEY_ELEMENTS':
                $("#KEY_ELEMENTS").val(value);
                break;
            case 'COUNT':
                $("#COUNT").val(value);
                break;
            case 'UNIT':
                $("#UNIT").val(value);
                break;
            case 'UNIT_PRICE':
                $("#UNIT_PRICE").val(value);
                break;
            case 'TOTAL_PRICE':
                $("#TOTAL_PRICE").val(value);
                break;
            case 'CURRENCY':
                $("#CURRENCY").val(value);
                break;
            case 'LEGAL_COUNT':
                $("#LEGAL_COUNT").val(value);
                break;
            case 'LEGAL_UNIT':
                $("#LEGAL_UNIT").val(value);
                break;
            case 'DESTINATION':
                $("#DESTINATION").val(value);
                break;
            case 'DESTINATION_CODE':
                $("#DESTINATION_CODE").val(value);
                break;
            case 'ORIGIN_COUNTRY':
                $("#ORIGIN_COUNTRY").val(value);
                break;
            case 'ORIGIN_COUNTRY_CODE':
                $("#ORIGIN_COUNTRY_CODE").val(value);
                break;
            case 'GOODS_NUMBER':
                $("#GOODS_NUMBER").val(value);
                break;
            case 'PACKAGE_TYPE':
                $("#PACKAGE_TYPE").val(value);
                break;
            case 'GOODS_NET_WEIGHT':
                $("#GOODS_NET_WEIGHT").val(value);
                break;
            case 'GOODS_GROSS_WEIGHT':
                $("#GOODS_GROSS_WEIGHT").val(value);
                break;
            case 'SECOND_COUNT':
                $("#SECOND_COUNT").val(value);
                break;
            case 'SECOND_UNIT':
                $("#SECOND_UNIT").val(value);
                break;
            case 'LEVYMODE':
                $("#GOODS_LEVYMODE").val(value);
                break;
            case 'ID':
                $("#ID").val(value);
                break;
            case 'OPERATION':
                break;
//			case 'CONTAINER_NO':
//				$("#CONTAINER_NO").val(value);
//				break;
            case 'VERSION_NO':
                $("#VERSION_NO").val(value);
                break;
            case 'PACKINGLIST_REMARK':
                $("#PACKINGLIST_REMARK").val(value);
                break;
        }
    });
    if (!$("#SECOND_UNIT").val() || $("#SECOND_UNIT").val() == "") {
        $("#SECOND_COUNT").attr("disabled", "disabled");
    }
}

function delGoods(obj) {
    var count = $("#goods_list table").find("tr").length;
    if (count > 2) {
        $(obj).parent().parent().remove();
        reflashIndex();
    } else {
        alert("不能删除");
    }
}

function copyGoods(obj) {
    var goodsLength = $("#goods_list table tr").length - 1;
    if (goodsLength == 20) {
        alert("报关商品录入项不能超过20项!");
        return;
    }
    var tr = $(obj).parent().parent().html();
    $("#goods_list table").append($("<tr>" + tr + "</tr>"));
    $("#goods_list table tr:last").find("td[name=ID]").html("");//设置复制那行的ID为空
//		$("#goods_list table tr:last").find("td[name=GOODS_MODE]").html("");//设置复制那行的要素为空
    reflashIndex();
}

function gotoTab() {
    var $li = $('#tab li');
    var $ul = $('#content ul');
    var $t = $li.parent().find(".current").index() + 1;
    $li.removeClass();
    $li.eq($t).addClass('current');
    $ul.css('display', 'none');
    $ul.eq($t).css('display', 'block');
    var isRecordInfo = $("#isRecordInfo").val();
    var RECORD_ID = $("#RECORD_ID").val();
    var SO = $("#SO").val();
    var CONTAINER_NO = $("#CONTAINER_NO").val();
    if ($t == 0) {
        //$("#RECORD_ID_DIV").show();
    } else if ($t == 1) {
        $("#SELLER").focus();
    } else if ($t == 2) {
        setValue();
        //$("#RECORD_ID_DIV").hide();
        $("#orderSave").show();
    } else {
        //$("#RECORD_ID_DIV").hide();
    }
    refreshGoodsTotal();//统计计价数量、净重、毛重等
}

function setValue() {
    var objArray2 = $("#outer ul").eq(3).find("label");
    objArray2.each(function (i, n) {
        var v = "";
        switch (i) {
            case 0:
                v = $("#SELLER").val();
                break;
            case 1:
                v = $("#SELLER_ADDRESS").val();
                break;
            case 2:
                v = $("#SELLER_PHONE").val();
                break;
            case 3:
                v = $("#SELLER_FAX").val();
                break;
            case 4:
                v = $("#BUYER").val();
                break;
            case 5:
                v = $("#GOODS_ADDR_SHOW").val();
                break;
            case 6:
                v = $("#FAHUO_COMPANY_NAME").val();
                break;
            case 7:
                v = $("#CONTRACT_DATE").val();
                break;
            case 8:
                v = $("#CONTRACT_NO").val();
                break;
            case 9:
                v = $("#INVOICE_NO").val();
                break;
            case 10:
                v = $("#LICENSE_NO").val();
                break;
            case 11:
                v = $("#LEVYMODE_SHOW").val();
                break;
            case 12:
                //运抵国
                v = $("#ARRIVED_COUNTRY_SHOW").val();
                break;
            case 13:
                //指运港
                v = $("#ARRIVED_PORT_SHOW").val();
                break;
            case 14:
                //总净重
                var sum_net_weight = 0;
                $("#goods_list table").find("tr").each(function (index) {
                    $(this).find("td").each(function (tdindex) {
                        var datasrc = this;
                        var data = datasrc.innerText;
                        switch (tdindex) {
                            case 16:
                                sum_net_weight = data - (-sum_net_weight);
                                break;
                        }
                    });
                });
                v = sum_net_weight;
                break;
            case 15:
                //总毛重
                var sum_gross_weight = 0;
                $("#goods_list table").find("tr").each(function (index) {
                    $(this).find("td").each(function (tdindex) {
                        var datasrc = this;
                        var data = datasrc.innerText;
                        switch (tdindex) {
                            case 17:
                                sum_gross_weight = data - (-sum_gross_weight);
                                break;
                        }
                    });
                });
                v = sum_gross_weight;
                break;
            case 16:
                v = $("#GOODS_PACKAGE").val();
                break;
            case 17:
                //无木质包装声明
                var checked = $("#outer ul").eq(2).find("input[type=radio]").eq(0).attr("checked");
                v =
                    "<input type='radio' " + (checked ? "checked='checked'" : "")
                    + " onclick='return false;' disabled='true' >" + "无木质包装声明";
                break;
            case 18:
                //木质包装声明+合格证
                var checked = $("#outer ul").eq(2).find("input[type=radio]").eq(1).attr("checked");
                v =
                    "<input type='radio' " + (checked ? "checked='checked'" : "")
                    + " onclick='return false;' disabled='true' >" + "木质包装声明+合格证";
                break;
            case 19:
                v = $("#CARTON").val();
                break;
            case 20:
                //总件数
                var sum_goods_number = 0;
                $("#goods_list table").find("tr").each(function (index) {
                    $(this).find("td").each(function (tdindex) {
                        var datasrc = this;
                        var data = datasrc.innerText;
                        switch (tdindex) {
                            case 15:
                                sum_goods_number = data - (-sum_goods_number);
                                break;
                        }
                    });
                });
                v = sum_goods_number;
                break;
            case 21:
                v = $("#TRADE_MODE_SHOW").val();
                break;
            case 22:
                v = $("#TRANSPORT_MODE").val();
                break;
            case 23:
                v = $("#LC_TYPE_SHOW").val();
                break;
            case 24:
                v = $("#DEAL_MODE_SHOW").val();
                break;
            case 25:
                v = $("#FREIGHT1").val();
                break;
            case 26:
                v = $("#FREIGHT2").val();
                break;
            case 27:
                v = $("#FREIGHT3").val();
                break;
            case 28:
                v = $("#PREMIUM1").val();
                break;
            case 29:
                v = $("#PREMIUM2").val();
                break;
            case 30:
                v = $("#PREMIUM3").val();
                break;
            case 31:
                v = $("#OTHERFEEL1").val();
                break;
            case 32:
                v = $("#OTHERFEEL2").val();
                break;
            case 33:
                v = $("#OTHERFEEL3").val();
                break;
            case 34:
                v = $("#REMARK").val();
                break;
        }
        $(n).html(v);
    });
}

function getIndex(objArray) {
    var index = "";
    objArray.each(function (i, n) {
        if ($(event.srcElement).attr("id") == $(n).attr("id")) {
            index = i;
            return false;
        }
    });
    return index;
};

/**
 * 设置默认值方法
 */
function setDefaultValue(inputSelect, value) {
    if ($(inputSelect).val() == "" || $(inputSelect).val() == undefined || $(inputSelect).val()
                                                                           == null) {
        $(inputSelect).val(value);
    }
}

$(function () {
    var isRecord = $("#isRecordInfo_val").val();
    var RECORD_ID = $("#RECORD_ID").val();
    if (isRecord && isRecord == "T") {
        $("#GOODS_MODE").attr("disabled", false);
    } else if (isRecord && isRecord == "F") {
        $("#GOODS_MODE").attr("disabled", true);
        $("#GOODS_MODE").attr("class", "disableInput");
    } else if (RECORD_ID && RECORD_ID != "") {
        $("#GOODS_MODE").attr("disabled", false);
    } else if (!RECORD_ID || RECORD_ID == "") {
        $("#GOODS_MODE").attr("disabled", true);
        $("#GOODS_MODE").attr("class", "disableInput");
    }
    if ((!isRecord || isRecord == "F") && (!RECORD_ID || RECORD_ID == "")) {
        $("th[lang=handbook_item_no]").attr("style", "display:none;");
        $("td[lang=handbook_item_no]").attr("style", "display:none;");
    }
//		$("#HANDBOOK_ITEM_NO").attr("disabled",true);//手册项号
    //$("#GOODS_MODE").attr("disabled",true);//规格型号
    $("#CODE_S").attr("disabled", true);//税号附号
    $("#CODE_S").attr("class", "disableInput");
    $("#LEGAL_UNIT").attr("disabled", true);//法定单位
    $("#LEGAL_UNIT").attr("class", "disableInput");
    $("#SECOND_UNIT").attr("disabled", true);//第二计量单位
    $("#SECOND_UNIT").attr("class", "disableInput");
    $("#UNIT_PRICE").attr("disabled", true);//单价
    $("#UNIT_PRICE").attr("class", "disableInput");
    var declareId = $("#declareId").val();
    //页面默认值
    if (declareId == null || declareId == "") {
        setDefaultValue("#CURRENCY", "美元");
        setDefaultValue("#TRADE_MODE_SHOW", "一般贸易");
        setDefaultValue("#TRADE_MODE", "0110");
        setDefaultValue("#LEVYMODE_SHOW", "一般征税");
        setDefaultValue("#LEVYMODE", "101");
        setDefaultValue("#DEAL_MODE_SHOW", "FOB");
        setDefaultValue("#DEAL_MODE", "3");
        setDefaultValue("#LC_TYPE_SHOW", "电汇");
        setDefaultValue("#LC_TYPE", "2");
        setDefaultValue("#REMARK", "结汇,退税");
        setDefaultValue("#GOODS_LEVYMODE", "照章征税");
        setDefaultValue("#CARTON", "N/M");
//			setDefaultValue("#EXPORT_PORT", "佛山新港");
//			setDefaultValue("#EXPORT_PORT_CODE", "5189");
//			setDefaultValue("#DECLARATION_PORT", "佛山新港");
//			setDefaultValue("#DECLARATION_PORT_CODE", "5189");
        setDefaultValue("#TRANSPORT_MODE", "水路运输");
        setDefaultValue("input[name='transport_mode_code']", "2");
        setDefaultValue("#declaretion_type", "通关无纸化");
        setDefaultValue("#WORK_TYPE", "进出闸口");
        setDefaultValue("#ORIGIN_COUNTRY", "中国");
        setDefaultValue("#ORIGIN_COUNTRY_CODE", "142");
    }

    //成交方式
    if ($("#DEAL_MODE_SHOW").val() == "FOB") {
        $("tr[lang=FREIGHT_TR]").hide();
        $("input[id^=FREIGHT][type!=hidden]").attr("disabled", true);
//			$("input[id^=FREIGHT][type!=hidden]").attr("class","disableInput");
        $("tr[lang=PREMIUM_TR]").hide();
        $("input[id^=PREMIUM][type!=hidden]").attr("disabled", true);
//			$("input[id^=PREMIUM][type!=hidden]").attr("class","disableInput");
        $("tr[lang=OTHERFEEL_TR]").hide();
        $("input[id^=OTHERFEEL][type!=hidden]").attr("disabled", true);
//			$("input[id^=OTHERFEEL][type!=hidden]").attr("class","disableInput");
    } else {
        $("tr[lang=FREIGHT_TR]").show();
        $("input[id^=FREIGHT][type!=hidden]").attr("disabled", false);
        $("tr[lang=PREMIUM_TR]").show();
        $("input[id^=PREMIUM][type!=hidden]").attr("disabled", false);
        $("tr[lang=OTHERFEEL_TR]").show();
        $("input[id^=OTHERFEEL][type!=hidden]").attr("disabled", false);
    }
    enterNext();
});

//回车跳转功能
function enterNext() {
    var objArray = $("#outer input[id][type!=hidden][disabled!=disabled]");
    objArray.bind('keypress', function (event) {
        if (event.keyCode == 13) {
            var inputIndex = getIndex(objArray);
            var nextInput = objArray.eq(++inputIndex);
            //alert($(this).attr("id"));
            if ("CONTAINER_NO" == $(this).attr("id")) {
                if ($("#isRecordInfo_val").val() == "F") {
                    $("#NAME").focus();
                } else {
                    nextInput.select();
                }
            } else if ("NAME" == $(this).attr("id")) {
                var name = $(this).val();
                var url = encodeURI(encodeURI('goodsView-main?goodsViewName=' + name));
                jw.dialog({
                              iframe: url,
                              width: 800, height: 570
                          });
                nextInput.select();
            } else if ("LEGAL_COUNT" == $(this).attr("id")) {
                if (!$("#SECOND_UNIT").val() || $("#SECOND_UNIT").val() == "") {
//						$("#GOODS_NUMBER").focus();
                    $("#GOODS_NUMBER").select();
                } else {
//						nextInput.focus();
                    nextInput.select();
                }
            } else if ("ORIGIN_COUNTRY" == $(this).attr("id")) {
                $("#PACKINGLIST_REMARK").select();

            } else if ("REMARK" == $(this).attr("id")) {
                gotoTab();
            } else if ("CONCRETE_GOODS_PACKAGE" == $(this).attr("id")) {
                $("#CARTON").select();
            } else if ("HANDBOOK_ITEM_NO" == $(this).attr("id")) {
                $("#NAME").select();
            } else if ("KEY_ELEMENTS" == $(this).attr("id")) {
                $("#CODE_T").select();
            } else if ("PACKINGLIST_REMARK" == $(this).attr("id")) {
                confirmDeclare();
            } else {
                nextInput.select();
//					nextInput.focus();
            }
        }
    });
}

//包装种类为其他时需填写具体包装种类
$("#GOODS_PACKAGE").bind("blur", function (event) {
    var goods_package = $("#GOODS_PACKAGE").val();
    if (goods_package == "其它") {
        $("#CONCRETE_GOODS_PACKAGE").show();
        enterNext();
    } else {
        $("#CONCRETE_GOODS_PACKAGE").hide();
        $("#CONCRETE_GOODS_PACKAGE").val("");
        if ($("#OTHER_GOODS_ADDR_SHOW").val() != "") {
            $("#REMARK").val($("#DECLARATION_PORT").val() + ",结汇,退税; 其他货源地：" + $(
                                 "#OTHER_GOODS_ADDR_SHOW").val());
        } else {
            $("#REMARK").val($("#DECLARATION_PORT").val() + ",结汇,退税");
        }
        enterNext();
    }
});

//通过成交方式锁定费用输入框
$("#DEAL_MODE_SHOW").bind("blur", function (event) {
    var deal = $("#DEAL_MODE").val();
    switch (deal) {
        case "1":
            $("tr[lang=FREIGHT_TR]").show();
            $("input[id^=FREIGHT][type!=hidden]").attr("disabled", false);
            $("input[id^=FREIGHT][type!=hidden]").eq(0).focus();
            $("tr[lang=PREMIUM_TR]").show();
            $("input[id^=PREMIUM][type!=hidden]").attr("disabled", false);
            $("tr[lang=OTHERFEEL_TR]").show();
            $("input[id^=OTHERFEEL][type!=hidden]").attr("disabled", false);
            break;
        case "2":
            $("tr[lang=FREIGHT_TR]").show();
            $("input[id^=FREIGHT][type!=hidden]").attr("disabled", false);
            $("input[id^=FREIGHT][type!=hidden]").eq(0).focus();
            $("tr[lang=PREMIUM_TR]").hide();
            $("input[id^=PREMIUM][type!=hidden]").attr("disabled", true);
            $("input[id^=PREMIUM][type!=hidden]").attr("class", "disableInput");
            $("tr[lang=OTHERFEEL_TR]").show();
            $("input[id^=OTHERFEEL][type!=hidden]").attr("disabled", false);
            break;
        case "3":
            $("tr[lang=FREIGHT_TR]").hide();
            $("input[id^=FREIGHT][type!=hidden]").attr("disabled", true);
            $("input[id^=FREIGHT][type!=hidden]").attr("class", "disableInput");
            $("tr[lang=PREMIUM_TR]").hide();
            $("input[id^=PREMIUM][type!=hidden]").attr("disabled", true);
            $("input[id^=PREMIUM][type!=hidden]").attr("class", "disableInput");
            $("tr[lang=OTHERFEEL_TR]").hide();
            $("input[id^=OTHERFEEL][type!=hidden]").attr("disabled", true);
            $("input[id^=OTHERFEEL][type!=hidden]").attr("class", "disableInput");
            break;
        default:
            break;
    }
    enterNext();
});


